Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

245
Visualizações
How to add delay in a function call in JS/Vue JS ("this" gets undefined)
updateGraphCurrentIndex(value) {
      // Returns a Promise that resolves after "ms" Milliseconds
      const timer = function(ms) {
        return new Promise(res => setTimeout(res, ms));
      };

      this.$vs.loading({ container: "#compare-chart", type: "point" });

      console.log("///////selected TAB Recieved", value
        ,"///////// tickersss", this.selectedTickers);

      this.current_index = value;

      // clear data on Graph
      this.selectedTickers.forEach((ticker) => {
        this.clearTickerDataGraph(ticker);
      });

      // display data on the table

      console.log("////////selectedTikerss", this.selectedTickers[0]);
      async function load() {
        try {
           console.log("////////WHAT IS THIS", this);
          for (let index = 0; index < this.selectedTickers.length; index++) {
            console.log("Helllo ", index);
            console.log("////////////i is called here", this.selectedTickers[index]);
            this.tickerDataGraph(this.selectedTickers[index]);
            await timer(3000);
          }
        } catch (error) {
          console.log("///////////error in Load", error);
        }
      }
     
      load();

      // this.selectedTickers.forEach((ticker, i) => {
      //   setTimeout(()=> {
      //     this.tickerDataGraph(ticker);
      //     // await timer(3000); // then the created Promise can be awaited
      //   }, 3000);
      // });

      // ['IBM', 'APPL']
      // this.selectedTickers.forEach((ticker) => {
      //   this.tickerDataGraph(ticker);
      // });

    }

I want my load method to run after 3 seconds but as the flow of execution enters the load method, I get this error Cannot read properties of undefined (reading 'selectedTickers'). Actually, this gets undefined inside the async load method. The this.tickerDataGraph(this.selectedTickers[index]) contains api calls that I want to delay.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda